home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / PopupItem.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.8 KB  |  104 lines  |  [TEXT/CWIE]

  1. // PopupItem.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. /** ListItem subclass representing a single entry in the ListView maintained by
  10.   * a Popup.
  11.   * @see ListView
  12.   */
  13.  
  14. public class PopupItem extends ListItem {
  15.     Popup   popup;
  16.  
  17.     final static String       POPUP_KEY = "popup";
  18.  
  19.  
  20.     /** Constructs an empty PopupItem.
  21.       */
  22.     public PopupItem() {
  23.         super();
  24.     }
  25.  
  26.     /** Sets the Popup that maintains this PopupItem.
  27.       */
  28.     public void setPopup(Popup aPopup) {
  29.         popup = aPopup;
  30.     }
  31.  
  32.     /** Returns the Popup that maintains this PopupItem.
  33.       * @see #setPopup
  34.       */
  35.     public Popup popup() {
  36.         return popup;
  37.     }
  38.  
  39.     /** Called by ListView to draw the PopupItem.
  40.       */
  41.     public void drawInRect(Graphics g, Rect boundsRect) {
  42.         int        width, height;
  43.         Image      popupImage;
  44.         PopupItem  selectedItem;
  45.  
  46.         super.drawInRect(g, boundsRect);
  47.  
  48.         if (popup != null) {
  49.             selectedItem = (PopupItem)popup.selectedItem();
  50.             if (selectedItem.equals(this)) {
  51.                 popupImage = popup.popupImage();
  52.  
  53.                 if (popupImage != null) {
  54.                     width = popupImage.width();
  55.                     height = popupImage.height();
  56.                 } else {
  57.                     width = height = 0;
  58.                 }
  59.  
  60.                 if (selected) {
  61.                     g.setColor(selectedColor);
  62.                 } else {
  63.                     g.setColor(listView.backgroundColor());
  64.                 }
  65.  
  66.                 g.fillRect(boundsRect.x + boundsRect.width - width - 4,
  67.                            boundsRect.y, width + 4, boundsRect.height);
  68.  
  69.                 if (popupImage != null) {
  70.                     popupImage.drawAt(g, boundsRect.x + boundsRect.width -
  71.                                       width - 2,
  72.                                       boundsRect.y +
  73.                                       (boundsRect.height - height)/2);
  74.                 }
  75.             }
  76.         }
  77.     }
  78.  
  79.     /** Describes the PopupItem class' information.
  80.       * @see Codable#describeClassInfo
  81.       */
  82.     public void describeClassInfo(ClassInfo info) {
  83.         super.describeClassInfo(info);
  84.         info.addClass("netscape.application.PopupItem", 1);
  85.         info.addField(POPUP_KEY, OBJECT_TYPE);
  86.     }
  87.  
  88.     /** Archives the PopupItem instance.
  89.       * @see Codable#encode
  90.       */
  91.     public void encode(Encoder encoder) throws CodingException {
  92.         super.encode(encoder);
  93.         encoder.encodeObject(POPUP_KEY, popup);
  94.     }
  95.  
  96.     /** Unarchives the PopupItem instance.
  97.       * @see Codable#decode
  98.       */
  99.     public void decode(Decoder decoder) throws CodingException {
  100.         super.decode(decoder);
  101.         popup = (Popup)decoder.decodeObject(POPUP_KEY);
  102.     }
  103. }
  104.